﻿// JScript 文件
var hkey_root,hkey_path,hkey_key
hkey_root="HKEY_CURRENT_USER"
hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"

//document.write("<object ID='WebBrowser1' WIDTH='0' HEIGHT='0' classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2' height='0' width='0'></object>"); 

//设置网页打印的页眉页脚为空
function pagesetup_null()
{
    try{
    var RegWsh = new ActiveXObject("WScript.Shell")
    hkey_key="header"
    RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
    hkey_key="footer"
    RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"")
    }catch(e){}
}
function printsetup()
{
    bdhtml=window.document.body.innerHTML;
    WebBrowser1.execwb(8,1); 
    window.document.body.innerHTML=bdhtml;
}
function printpreview() 
{  
    pagesetup_null();
    bdhtml=window.document.body.innerHTML;
    sprnstr="<!--STARTPRINT-->";
    eprnstr="<!--ENDPRINT-->";
    prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr));
    prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
    window.document.body.innerHTML=prnhtml;
    
    WebBrowser1.execwb(7,1); 
    window.document.body.innerHTML=bdhtml;                
}
function printit()
{
    if(confirm('确定打印吗?'))
    {
        bdhtml=window.document.body.innerHTML;
        sprnstr="<!--STARTPRINT-->";
        eprnstr="<!--ENDPRINT-->";
        prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr));
        prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
        window.document.body.innerHTML=prnhtml;

        WebBrowser1.execwb(6,6);
        window.document.body.innerHTML=bdhtml;
    } 
}

//不用控件WebBrowser的打印方式
function doPrintWithOtherMethod()
{
    if(confirm('确定打印吗?'))
    {
        bdhtml=window.document.body.innerHTML;
        sprnstr="<!--STARTPRINT-->";
        eprnstr="<!--ENDPRINT-->";
        prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr));
        prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
        window.document.body.innerHTML=prnhtml;
        window.print();
        window.document.body.innerHTML=bdhtml;
    } 
}